package com.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.ExamManage;
import com.exam.serviceimpl.ExamManageServiceImpl;
import com.exam.util.ApiResultHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "考试管理表")
@RestController
public class ExamManageController {

    @Resource
    private ExamManageServiceImpl examManageService;

    @ApiOperation(value = "不分页查询所有试卷")
    @GetMapping("/exams")
    public ApiResult findAll(){
        return examManageService.findAll();
    }

    @ApiOperation(value = "分页查询所有试卷")
    @GetMapping("/exams/{page}/{size}")
    public ApiResult findAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return examManageService.findAll(page,size);
    }

    @ApiOperation(value = "根据考试ID查找当前考生的信息")
    @GetMapping("/exam/{examCode}")
    public ApiResult findById(@PathVariable("examCode") Integer examCode){
        return examManageService.findById(examCode);
    }

    @ApiOperation(value = "根据考试ID删除当前考生的信息")
    @DeleteMapping("/exam/{examCode}")
    public ApiResult deleteById(@PathVariable("examCode") Integer examCode){
        return examManageService.delete(examCode);
    }

    @ApiOperation(value = "修改考试信息")
    @PutMapping("/exam")
    public ApiResult update(@RequestBody ExamManage exammanage){
        return  examManageService.update(exammanage);
    }


    @ApiOperation(value = "添加考试信息")
    @PostMapping("/exam")
    public ApiResult add(@RequestBody ExamManage exammanage){
        return examManageService.add(exammanage);
    }

    @ApiOperation(value = "查询最后一条记录的paperId,返回给前端达到自增效果")
    @GetMapping("/examManagePaperId")
    public ApiResult findOnlyPaperId() {
        return examManageService.findOnlyPaperId();
    }
}
